<script type='text/javascript' src='${base}/dwr/engine.js'></script>
<script type='text/javascript' src='${base}/dwr/util.js'></script>
<script type='text/javascript' src='${base}/dwr/interface/backPurviewService.js'></script>

<script type="text/javascript">
	function checkInfo(){
		if(j.trim(j("#Pname").val()).length ==0){
			alert("请填写权限名");
			return false;
		}
		if(j.trim(j("#PactionName").val()).length==0){
			alert("请填写权限路径");
			return false;
		}
		if(j.trim(j("#PsortNo").val()).length==0){
			alert("请填写序号");
			return false;
		}
		var re = /^\d*$/;
	    if (!re.test(j.trim(j("#PsortNo").val()))){
	    	 alert("序号必须是正整数或者0");
	    	 return false;
	    }
	    return true;
	}

	function savePurview(){
		if(!checkInfo()){
			return;
		}
		
		dwr.engine.setAsync(false);
		var callBack=function(data){
			if(data!=null){
				alert(data);
			}else{
				parent.addSuccess("backPurviewManage.action");
				closerparent();
			}
		}
		var Purview={
				"name":j.trim(j("#Pname").val()),
				"actionName":j.trim(j("#PactionName").val()),
				"sortNo":j.trim(j("#PsortNo").val()),
				"level":"${backPurview.level?if_exists}"
		}
		backPurviewService.saveBackPurviewDWR(Purview,"${parentPurviewId?if_exists}",callBack)
		dwr.engine.setAsync(true);
	}

	function editPurview(){
		if(!checkInfo()){
			return;
		}
		dwr.engine.setAsync(false);
		var callBack=function(data){
			parent.addSuccess("backPurviewManage.action")
			closerparent();
		}
		var Purview={
				"id":"${backPurview.id?if_exists}",
				"name":j.trim(j("#Pname").val()),
				"actionName":j.trim(j("#PactionName").val()),
				"sortNo":j.trim(j("#PsortNo").val())
		}
		backPurviewService.eidtBackPurviewDWR(Purview,callBack)
		dwr.engine.setAsync(true);
		
	}
	function closerparent(){
	    parent.floatboxclose(false);
	}
</script>

<form>
<table border="0" class="tb tb2" >
	<#if parentPurviewName?exists>
		<tr><td style="font-weight: bold;font-size: 13px">父级权限</td><td>${parentPurviewName?if_exists}</td></tr>
	</#if>
	<tr>
		<td>权限名</td>
		<td><input name="" id="Pname" type="text" value="${backPurview.name?if_exists}"/></td>
	</tr>
	<tr>
		<td>权限路径</td> 
		<td><input name="" id="PactionName" type="text" value="${backPurview.actionName?if_exists}"/>.action</td>
	</tr>
	<tr>
		<td>序号</td>
		<td><input maxlength="4" name="" id="PsortNo" type="text" <#if control?exists && control= "EDIT">value="${backPurview.sortNo?if_exists}"</#if>/></td>
	</tr>
	<tr>
		<td colspan="2">
			<#if control?exists && control= "EDIT">
				<input type="button" value="修改" onclick="editPurview()" style="width: 100"/>&nbsp;&nbsp;&nbsp;&nbsp;
			<#else>
				<input type="button" value="提交" onclick="savePurview()" style="width: 100"/>&nbsp;&nbsp;&nbsp;&nbsp;
			</#if>
			<input type="reset" value="重置" style="width: 100"/>&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="reset" value="取消" style="width: 100" onclick="closerparent()"/>
		</td>
	</tr>
</table>
</form>